package com.jiutianniao.p2p.acctrans.core.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.jiutianniao.p2p.acctrans.core.dal.dao.TransLogDao;
import com.jiutianniao.p2p.acctrans.core.dal.model.TransLogDO;
import com.jiutianniao.p2p.acctrans.core.service.TransLogService;
import com.jiutianniao.p2p.base.model.Sequence;
import com.jiutianniao.p2p.base.service.SequenceService;

@Service("TransLogService")
public class TransLogServiceImpl implements TransLogService {
	SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");

	Long maxSequenceId = 99999999L;

	Long minSequenceId = 1L;
	@Resource
	private TransLogDao transLogDao;

	@Resource
	private SequenceService sequnceService;

	@Override
	public void saveTransLog(TransLogDO transLogDO) {
		transLogDao.save(transLogDO);
	}

	@Override
	public Long getTransLogSequenceId() {
		Long id = sequnceService.getNextBySequenceName(
				Sequence.SequenceName.TRANS_LOG_SEQUENCE.name(), maxSequenceId);
		return id;
	}

	@Override
	public Long getTransLogId() {
		Long sequenceId = this.getTransLogSequenceId();
		String str = String.format("%08d", sequenceId);
		str = format.format(new Date()) + str;
		return Long.valueOf(str);
	}

}
